﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IVS.MathLibrary
{
    /// <summary>
    /// Class provides basic mathematic functions.
    /// </summary>
    public class Arithmetic
    {
        #region ------------------------------ CONSTRUCTION ------------------------------

        /// <summary>
        /// Creates new instance of Arithmetic class.
        /// </summary>
        public Arithmetic ()
        { }

        #endregion

        #region ------------------------------ PUBLIC METHODS ------------------------------

        /// <summary>
        /// Adds two real numbers. Returns sum.
        /// </summary>
        /// <param name="x">first number</param>
        /// <param name="y">second number</param>
        /// <returns></returns>
        public double Addition (double x, double y)
        {
            return x + y;
        }

        /// <summary>
        /// Subtract two real numbers. Returns difference.
        /// </summary>
        /// <param name="x">first number</param>
        /// <param name="y">second number</param>
        /// <returns></returns>
        public double Subtraction (double x, double y)
        {
            return x - y;
        }

        /// <summary>
        /// Multiply two real numbers. Returns conjuction.
        /// </summary>
        /// <param name="x">first number</param>
        /// <param name="y">second number</param>
        /// <returns></returns>
        public double Multiplication (double x, double y)
        {
            return x * y;
        }

        /// <summary>
        /// Divide two real numbers. Returns fraction.
        /// </summary>
        /// <param name="x">first number</param>
        /// <param name="y">second number</param>
        /// <returns></returns>
        public double Division (double x, double y)
        {
            if (y == 0)
                return Double.NaN;
            else
                return x / y;
        }

        /// <summary>
        /// Returns a specified number raised to the specified power.
        /// </summary>
        /// <param name="x">a double-precision floating-point number to be raised to a power.</param>
        /// <param name="y">a double-precision floating-point number that specifies a power.</param>
        /// <returns></returns>
        public double Power (double x, double y)
        {
            return Math.Pow(x, y);
        }

        /// <summary>
        /// Returns the square root of a specified number.
        /// </summary>
        /// <param name="x">a number</param>
        /// <returns></returns>
        public double SquareRoot (double x)
        {
            return Math.Sqrt(x);
        }

        /// <summary>
        /// Returns factorial of a specified number.
        /// </summary>
        /// <param name="x">a number</param>
        /// <returns></returns>
        public double Factorial (double x)
        {
            double result = 1;
            while (x > 1)
            {
                result *= x;
                x--;
            }
            return result;
        }

        /// <summary>
        /// Returns inverted value.
        /// </summary>
        /// <param name="x">a number</param>
        /// <returns></returns>
        public double Inversion (double x)
        {
            if (x == 0)
                return double.NaN;
            else
                return 1 / x;
        }

        /// <summary>
        /// Returns negated value.
        /// </summary>
        /// <param name="x">a number</param>
        /// <returns></returns>
        public double Negation (double x)
        {
            return -x;
        }

        #endregion
    }
}
